<?php

/**
 * User registration form
 *
 */
class Application_Form_Register extends Zend_Form
{

    public function init()
    {
        $this->setMethod('POST');
        $this->setAction(Zend_Registry::get('view')->fixUrl('user/register'));
        
        $nicename=new Zend_Form_Element_Text('nicename');
        $nicename->setLabel('Full name')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 2,
                        'max' => 255
                    )
              )
              ->addDecorator(new Application_Form_RegisterDecorator())
              ->setRequired(false);
        
        $login=new Zend_Form_Element_Text('login');
        $login->setLabel('Login')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 4,
                        'max' => 255
                    )
              )
              ->addValidator(
                    new Application_Form_RegisterLoginValidator(),
                    true
                    )
              ->addDecorator(new Application_Form_RegisterDecorator())
              ->setRequired(true);
         
        $password=new Zend_Form_Element_Password('password');
        $password->setLabel('Password')
              ->addFilter('StringTrim')
              ->addFilter('StripTags')
              ->addValidator(
                    'StringLength',
                    true,
                    array(
                        'min' => 5,
                        'max' => 255
                    )
              )
              ->addDecorator(new Application_Form_RegisterDecorator())
              ->setRequired(true);
              
        $password_re=new Zend_Form_Element_Password('password_re');
        $password_re->setLabel('Retype password')
              ->addFilter('StringTrim')
              ->addValidator(
                    'identical',
                    true,
                    array(
                        'min' => 5,
                        'max' => 255,
                        'token' => 'password'
                    )
              )
              ->addDecorator(new Application_Form_RegisterDecorator())
              ->setRequired(true);
              
        $email=new Zend_Form_Element_Text('email');
        $email->setLabel('E-Mail')
              ->addFilter('StringTrim')
              ->addValidator(
                    'EmailAddress',
                    true
              )
              ->addValidator(
                    new Application_Form_RegisterEmailValidator(),
                    true
                    )
              ->addDecorator(new Application_Form_RegisterDecorator())
              ->setRequired(true);
              
         $this->addElements(array(
            $nicename,
            $login,
            $password,
            $password_re,
            $email
         ));       
         
         $this->addElement('captcha', 'captcha', array(
            'label'      => 'CAPTCHA',
            'captcha'    => array(
                'captcha' => 'Image',
                'font' => ROOT_DIR.'/data/misc/FreeSerifBold.ttf',
                'fontSize' => 24,
                'imgDir' => ROOT_DIR.'/data/tmp/captcha',
                'imgUrl' => Zend_Registry::get('view')->baseUrl('data/tmp/captcha'),
                'wordLen' => 6,
                'timeout' => 300,
                'width' => 200,
                'height' => 50
            ),
            'decorators' => array(
                                new Application_Form_RegisterDecorator()
                              ),
            'required'   => true
         ));
  
         $submit=new Zend_Form_Element_Submit('submit');
         $submit->setValue('Sign Up')
                ->setLabel('')
                ->addDecorator(new Application_Form_RegisterDecorator());
               
         $csrf=new Zend_Form_Element_Hash('csrf',array('salt' => 'userReg'));
         $csrf->setOptions(array(
                            'ignore' => true
                        ))
              ->addDecorator(new Application_Form_RegisterDecorator());
        
         $this->addElements(array(
            $submit,
            $csrf
         ));    
    }


}

